# -*- coding: utf-8 -*-
"""
    @project: pythonProject
    @Author：HanYonghua
    @file： rpctest1.py
    @date：2025/8/5 10:38
    @blogs: https://www.ncatest.com.cn
"""

# test_rpc_client.py
import zmq
import json

context = zmq.Context()
dealer = context.socket(zmq.DEALER)
dealer.setsockopt(zmq.IDENTITY, b"test_client")  # 必须设置身份
dealer.connect("tcp://localhost:5555")

# 构建合法请求
valid_request = {
    "jsonrpc": "2.0",
    "method": "add",
    "params": [3, 5],
    "id": 1
}

# 构建非法请求（测试错误处理）
invalid_request = {
    "jsonrpc": "2.0",
    #"method": 123,  # 非字符串method
    "method": "GetInfo",
    "id": 2
}

config_request = {
    "jsonrpc": "2.0",
    "method": "config",
    "params": {"DebuggerUrl": "tcp://localhost:5555", "DebugEnable": True},
    "id": 1
}

def send_request(request):
    dealer.send(json.dumps(request).encode())
    frames = dealer.recv_multipart()
    print("Response:", json.loads(frames[0].decode()))

# 测试用例
send_request(valid_request)    # 应返回正确结果
send_request(config_request)  # 应返回错误响应

dealer.close()
